﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Interfaces;
using LinFu.IoC.Configuration;

namespace CoreEx.MicroMapper.Implementation
{
        [Factory(typeof(IMicroMapper<,>))]
        public class MicroMapperFactory : IFactory
        {                     
            public object CreateInstance(IFactoryRequest request)
            {
                Type mapperType = typeof(MicroMapper<,>);
                Type genericMapperType = mapperType.MakeGenericType(request.ServiceType.GetGenericArguments());
                object instance = Activator.CreateInstance(genericMapperType);
                ((IInitialize)instance).Initialize(request.Container);
                return instance;
            }
        }
}
